import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

class NativePageChannel {

  static bool _initialized = false;
  static const MethodChannel _channel = MethodChannel('native_page_channel');
  static late String currentPageName;

  static void init() {
    if (_initialized) {
      return;
    }
    _channel.setMethodCallHandler(handleMethodCall);

    _initialized = true;
  }

  static Future<dynamic> handleMethodCall(MethodCall call) {
    print('NativePageChannel flutter收到方法名:${call.method},参数:${call.arguments}');

    return Future(() => 2);
  }

  static Future<String> getMeasurementUnit() async {
    String ret = await _channel.invokeMethod('getMeasurementUnit');
    if (kDebugMode) {
      print("NativePageChannel.getMeasurementUnit: $ret");
    }
    return Future(() => ret);
  }
}